MAPS

Ridgeline Map

R Markdown


Section

Subsection

##           used (Mb) gc trigger  (Mb) max used (Mb)
## Ncells 1052157 56.2    2180487 116.5  1329527 71.1
## Vcells 1768426 13.5    8388608  64.0  2364878 18.1
##        y                x         population     
##  Min.   :  0.00   Min.   :  0   Min.   :      0  
##  1st Qu.: 49.75   1st Qu.:125   1st Qu.:  24967  
##  Median : 99.50   Median :251   Median :  64137  
##  Mean   : 99.50   Mean   :251   Mean   : 190686  
##  3rd Qu.:149.25   3rd Qu.:377   3rd Qu.: 183281  
##  Max.   :199.00   Max.   :502   Max.   :6739331  
##                                 NA's   :85483

Section

Subsection

Section

Subsection

range01 <- function(x){(x-min(x))/(max(x)-min(x))}
color_condition <- function(x) { ifelse(x==0, "transparent", "#666666")  }

#Add 180 to the latitude to remove negatives in southern hemisphere, then order them.
xyz_df_zero$npop <- range01(xyz_df_zero$population) * 0.2
xyz_df_zero$ny<-range01(xyz_df_zero$rank)
xyz_df_zero$nx<-range01(xyz_df_zero$x)
xyz_df_zero$ord <- xyz_df_zero$ny
xyz_df_zero_s <- xyz_df_zero[order(-xyz_df_zero$ord),]

v2 <- ggplot()
for (i in unique(xyz_df_zero_s$ord))
{
#print(i)
v2 <- v2 +
  geom_polygon(data = xyz_df_zero_s[xyz_df_zero_s$ord==i,], aes(nx, npop+ny, group = ny ), size=0.2, fill="white", color="white") + 
  # geom_polygon(data = xyz_df_zero_s[xyz_df_zero_s$ord==i,], aes(nx, npop+ny, group = ny, fill = population ), size=0.2, color="white") + 
  geom_path(data = xyz_df_zero_s[xyz_df_zero_s$ord==i,], 
            aes(nx, npop+ny, group = ny ), 
            color = color_condition(xyz_df_zero_s[xyz_df_zero_s$ord==i,]$npop), size = 0.2, lineend = "round")
}

#show plot!
v2 +
  scale_x_continuous(expand = c(0,0)) +
  scale_y_continuous(expand = c(0,0)) +
  theme_bw() +
  theme_opts

Section

Subsection

#ggsave(filename = "world-population-ridgeline-xyz-v1.svg", plot = v1, width=12, height=6)
#ggsave(filename = "world-population-ridgeline-xyz-v2.svg", plot = v2, width=12, height=6)

Exercises and practice

Knime and R practice solutions

References

The citations and data sources used for this case

Source